package com.chankudo.demo3;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.BeanClassLoaderAware;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.BeanFactoryAware;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;

public class LifeCycleDemo 
implements BeanNameAware, BeanClassLoaderAware, BeanFactoryAware,
InitializingBean, DisposableBean
{
    
    public LifeCycleDemo() {
        System.out.println("---LifeCycleDemo()--->");
    }

    @Override
    public void setBeanName(String name) {
        // 这个方法可以获取到xml里面配置的bean的名称
        // 例如可以这么用 this.name = name
        System.out.println("---setBeanName--->");
    }

    @Override
	public void setBeanClassLoader(ClassLoader classLoader) {
		
		System.out.println("---setBeanClassLoader--->");
	}

	@Override
	public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        // 可以通过这个方法获取到容器
        // 然后通过容易访问到与这个类相关联的一些类
		System.out.println("---setBeanFactory--->");	
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        
        System.out.println("---afterPropertiesSet--->");
    }
    
    //自定义的初始化函数
    public void myInitMethod(){

        System.out.println("---myInitMethod--->");
    }

    //自定义的析构函数
    public void myDestoryMethod(){

        System.out.println("---myDestoryMethod--->");
    }

    @Override
    public void destroy() throws Exception {

        System.out.println("---destroy--->");
    }



	
    
}
